<%--
  Created by IntelliJ IDEA.
  User: Mac
  Date: 2020/12/24
  Time: 10:41
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%String path = request.getContextPath()+"/";%>
<!DOCTYPE html>
<html>
<head>
    <base href="<%=path%>">
    <meta charset="utf-8">
    <title>角色新增</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="layui/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="//at.alicdn.com/t/font_tnyc012u2rlwstt9.css" media="all" />
    <link rel="stylesheet" href="layui/css/user.css" media="all" />
    <style type="text/css">
        .layui-form-item .layui-inline{ width:33.333%; float:left; margin-right:0; }
        @media(max-width:1240px){
            .layui-form-item .layui-inline{ width:100%; float:none; }
        }
    </style>
</head>
<body class="childrenBody">
<form class="layui-form" style="width:80%;" id="form1">
    <input type="hidden" name="id" value="${role.id}"/>

    <div class="layui-form-item">
        <label class="layui-form-label">角色名称</label>
        <div class="layui-input-block">
            <input type="text" name="roleName" value="${role.roleName}" class="layui-input userName" lay-verify="required" placeholder="请输入登录名">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <c:set var="status" value="1"></c:set>
            <c:if test="${not empty role}">
                <c:set var="status" value="${role.status}"/>
            </c:if>
            <input type="hidden" name="status" value="${status}" id="status"/>
            <input type="checkbox" name="switch"  lay-filter="status"  lay-text="启用|停用" checked lay-skin="switch">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn submit" lay-submit="" lay-filter="addUser" type="button">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script type="text/javascript" src="layui/layui/layui.js"></script>
<script type="text/javascript">
    layui.config({
        base : "js/"
    }).use(['form','layer','laypage','jquery'],function() {
        form = layui.form();
        $=layui.jquery;
        var layer = layui.layer;

        $('.submit').click(function () {
            let data = $("#form1").serialize();

            $.getJSON("role/save?"+data,function (ref) {
                if (ref.sta == 1){
                    layer.msg(ref.msg)

                    parent.layer.closeAll();
                    var roleName = parent.document.getElementById("roleName").value;
                    var pageNumber = parent.document.getElementById("pageNumber").value;
                    parent.loadData(roleName,pageNumber);
                    // parent.location.reload();

                }else {
                    layer.msg(ref.msg)
                }
            })
        })


    });
</script>
</body>
</html>
